34 typedef typename std::map<TimeStamp, T>::iterator
Iterator;
118 const double& _time_tolerance);
124 const double& _time_tolerance1,
126 const double& _time_tolerance2);
140 const double& _time_tolerance)
const
142 assert(_time_stamp.
ok() &&
"Buffer: invalid timestamp!");
145 bool prev_exists = (post != container_.begin());
146 bool post_exists = (post != container_.end());
148 bool post_ok = post_exists && checkTimeTolerance(post->first, _time_stamp, _time_tolerance);
154 bool prev_ok = checkTimeTolerance(prev->first, _time_stamp, _time_tolerance);
156 if (prev_ok && !post_ok)
159 else if (!prev_ok && post_ok)
162 else if (prev_ok && post_ok)
164 if (std::fabs(post->first - _time_stamp) < std::fabs(prev->first - _time_stamp))
173 return container_.end();
178 const double& _time_tolerance)
180 assert(_time_stamp.
ok() &&
"Buffer: invalid timestamp!");
183 bool prev_exists = (post != container_.begin());
184 bool post_exists = (post != container_.end());
186 bool post_ok = post_exists && checkTimeTolerance(post->first, _time_stamp, _time_tolerance);
192 bool prev_ok = checkTimeTolerance(prev->first, _time_stamp, _time_tolerance);
194 if (prev_ok && !post_ok)
197 else if (!prev_ok && post_ok)
200 else if (prev_ok && post_ok)
202 if (std::fabs(post->first - _time_stamp) < std::fabs(prev->first - _time_stamp))
211 return container_.end();
217 assert(_time_stamp.
ok() &&
"Buffer: invalid timestamp!");
218 if (container_.empty())
return T();
220 auto it = selectIterator(_time_stamp, _time_tolerance);
224 if (it != container_.end())
235 assert(_time_stamp.
ok() &&
"Buffer: invalid timestamp!");
237 if (container_.empty())
return T();
241 if (container_.begin()->first < _time_stamp)
return container_.begin()->second;
244 if (checkTimeTolerance(container_.begin()->first, _time_stamp, _time_tolerance))
return container_.begin()->second;
253 assert(_time_stamp.
ok() &&
"Buffer: invalid timestamp!");
255 if (container_.empty())
return T();
259 if (container_.rbegin()->first > _time_stamp)
return container_.rbegin()->second;
262 if (checkTimeTolerance(container_.rbegin()->first, _time_stamp, _time_tolerance))
263 return container_.rbegin()->second;
273 if (container_.empty())
return T();
276 return container_.begin()->second;
283 if (container_.empty())
return T();
286 return container_.rbegin()->second;
292 assert(_time_stamp.
ok() &&
"Buffer: invalid timestamp!");
293 container_.emplace(_time_stamp, _element);
317 return container_.empty();
323 return container_.size();
329 assert(_time_stamp.
ok() &&
"Buffer: invalid timestamp!");
331 container_.erase(container_.begin(), post);
337 assert(_time_stamp.
ok() &&
"Buffer: invalid timestamp!");
339 container_.erase(container_.begin(), post);
344 const double& _time_tolerance1,
346 const double& _time_tolerance2)
348 double time_diff = std::fabs(_time_stamp1 - _time_stamp2);
349 double time_tol = std::min(_time_tolerance1, _time_tolerance2);
350 bool pass = time_diff <= time_tol;
357 const double& _time_tolerance)
359 double time_diff = std::fabs(_time_stamp1 - _time_stamp2);
360 bool pass = time_diff <= _time_tolerance;
375 void emplace(FrameBasePtr _frm);
385 void emplace(CaptureBasePtr _cap);
Buffer of Captures.
Definition: buffer.h:381
void emplace(CaptureBasePtr _cap)
Adds a capture to the buffer, with its time stamp.
Definition: buffer.cpp:30
Buffer of Frames.
Definition: buffer.h:371
void emplace(FrameBasePtr _frm)
Adds a frame to the buffer, with its time stamp.
Definition: buffer.cpp:25
Buffer of VectorComposite.
Definition: buffer.h:391
Buffer for arbitrary type objects.
Definition: buffer.h:32
static bool doubleCheckTimeTolerance(const TimeStamp &_time_stamp1, const double &_time_tolerance1, const TimeStamp &_time_stamp2, const double &_time_tolerance2)
Returns whether the time distance between two time stamps is smaller than or equal to the minimum of ...
Definition: buffer.h:343
SizeStd size(void) const
Returns the number of elements of the buffer.
Definition: buffer.h:321
std::map< TimeStamp, T >::iterator Iterator
Buffer iterator.
Definition: buffer.h:34
void clear()
Clears the buffer.
Definition: buffer.h:309
const std::map< TimeStamp, T > & getContainer() const
Returns the container with elements of the buffer.
Definition: buffer.h:297
void removeUpTo(const TimeStamp &_time_stamp)
Removes all elements in the buffer with a time stamp older than or equal to the specified.
Definition: buffer.h:327
std::map< TimeStamp, T >::const_iterator ConstIterator
Buffer const iterator.
Definition: buffer.h:35
void emplace(const TimeStamp &_time_stamp, const T &_element)
Adds an element to the buffer.
Definition: buffer.h:290
Iterator selectIterator(const TimeStamp &_time_stamp, const double &_time_tolerance)
Select an element iterator from the buffer (see the const version)
Definition: buffer.h:177
T select(const TimeStamp &_time_stamp, const double &_time_tolerance) const
Select an element from the buffer.
Definition: buffer.h:215
T selectFirst() const
Returns the oldest element (T() if empty)
Definition: buffer.h:270
Buffer()
Default constructor.
Definition: buffer.h:39
std::map< TimeStamp, T > & getContainer()
Returns the container with elements of the buffer.
Definition: buffer.h:303
T selectLast() const
Returns the newest element (T() if empty)
Definition: buffer.h:280
static bool checkTimeTolerance(const TimeStamp &_time_stamp1, const TimeStamp &_time_stamp2, const double &_time_tolerance)
Returns whether the time distance between two time stamps is smaller than or equal to the time tolera...
Definition: buffer.h:355
T selectLastAfter(const TimeStamp &_time_stamp, const double &_time_tolerance) const
Returns the newest element if it is newer than _time_stamp or within the time tolerance (T() otherwis...
Definition: buffer.h:251
~Buffer(void)
Destructor.
Definition: buffer.h:43
ConstIterator selectIterator(const TimeStamp &_time_stamp, const double &_time_tolerance) const
Select an element iterator from the buffer.
Definition: buffer.h:139
void removeUpToLower(const TimeStamp &_time_stamp)
Removes all elements in the buffer with a time stamp older than the specified.
Definition: buffer.h:335
bool empty() const
Returns whether the buffer is empty.
Definition: buffer.h:315
T selectFirstBefore(const TimeStamp &_time_stamp, const double &_time_tolerance) const
Returns the oldest element if it is older than _time_stamp or within the time tolerance (T() otherwis...
Definition: buffer.h:233
std::map< TimeStamp, T > container_
Main buffer container, ordered by time stamp.
Definition: buffer.h:129
TimeStamp implements basic functionalities for time stamps.
Definition: time_stamp.h:39
bool ok() const
Returns whether the time stamp has a valid value.
Definition: time_stamp.h:214
Composite of state vectors.
Definition: vector_composite.h:29
Definition: capture_base.h:23
std::size_t SizeStd
Other containers size type for the Wolf project.
Definition: wolf.h:66